package com.uzai.console.web.user;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.WechatBlacklistTypeEnum;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvIdDto;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvIdListDto;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvInfoDto;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvQuery;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.user.WechatBlacklistPrvService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.user.wechatblacklist.WechatBlacklistPrvInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户管理|云黑名单|私有黑名单
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "私有黑名单",tags = "用户管理|云黑名单|私有黑名单")
@ApiSort(15)
@RestController
public class WechatBlacklistPrvController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(WechatBlacklistPrvController.class);

    @Autowired
    private WechatBlacklistPrvService wechatBlacklistPrvService;

    @ApiOperation(value = "分页查询私有黑名单列表", notes = "分页查询私有黑名单列表", response = WechatBlacklistPrvInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/wechatBlacklistPrv/findWechatBlacklistPrvList")
    public Object findWechatBlacklistPrvList(@RequestBody WechatBlacklistPrvQuery wechatBlacklistPrvQuery){
        return wechatBlacklistPrvService.findWechatBlacklistPrvList(wechatBlacklistPrvQuery);
    }

//    @ApiOperation(value = "查询私有黑名单信息", notes = "查询私有黑名单信息", response = WechatBlacklistPrvInfoVo.class)
//    @ApiOperationSupport(order = 2)
//    @PostMapping("/wechatBlacklistPrv/findWechatBlacklistPrvInfo")
//    public Object findWechatBlacklistPrvInfo(@RequestBody WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto){
//        return wechatBlacklistPrvService.findWechatBlacklistPrvInfo(wechatBlacklistPrvIdDto);
//    }
//
//    @ApiOperation(value = "编辑私有黑名单信息", notes = "编辑私有黑名单信息")
//    @ApiOperationSupport(order = 3)
//    @PostMapping("/wechatBlacklistPrv/updateWechatBlacklistPrv")
//    public Object updateWechatBlacklistPrv(@RequestBody WechatBlacklistPrvInfoDto wechatBlacklistPrvInfoDto){
//        wechatBlacklistPrvService.updateWechatBlacklistPrv(wechatBlacklistPrvInfoDto);
//        return true;
//    }

    @SystemLogType(model = SystemModelEnum.WechatBlacklistPrv, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "移除私有黑名单", notes = "移除私有黑名单")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wechatBlacklistPrv/deleteWechatBlacklistPrv")
    public Object deleteWechatBlacklistPrv(@RequestBody WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto){
        wechatBlacklistPrvService.deleteWechatBlacklistPrv(wechatBlacklistPrvIdDto);
        try {
            //延迟1秒
            Thread.sleep(1000);
        }catch (Exception e){

        }
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WechatBlacklistPrv, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "批量移除私有黑名单", notes = "批量移除私有黑名单")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wechatBlacklistPrv/deleteWechatBlacklistPrv/batch")
    public Object batchDeleteWechatBlacklistPrv(@RequestBody WechatBlacklistPrvIdListDto wechatBlacklistPrvIdListDto){
        wechatBlacklistPrvService.batchDeleteWechatBlacklistPrv(wechatBlacklistPrvIdListDto);

        try {
            //延迟1秒
            Thread.sleep(1000);
        }catch (Exception e){

        }

        return true;
    }

    @SystemLogType(model = SystemModelEnum.WechatBlacklistPrv, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "共享至全网", notes = "共享至全网")
    @ApiOperationSupport(order = 5)
    @PostMapping("/wechatBlacklistPrv/shareWechatBlacklistPub")
    public Object shareWechatBlacklistPub(@RequestBody WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto){
        wechatBlacklistPrvService.shareWechatBlacklistPub(wechatBlacklistPrvIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WechatBlacklistPrv, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加私有黑名单", notes = "添加私有黑名单")
    @ApiOperationSupport(order = 6)
    @PostMapping("/wechatBlacklistPrv/addWechatBlacklistPrv")
    public Object addWechatBlacklistPrv(@RequestBody WechatBlacklistPrvInfoDto wechatBlacklistPrvInfoDto){
        wechatBlacklistPrvService.addWechatBlacklistPrv(wechatBlacklistPrvInfoDto);
        return true;
    }

    @ApiOperation(value = "查询黑名单类型下拉选择框列表", notes = "查询黑名单类型下拉选择框列表")
    @ApiOperationSupport(order = 7)
    @PostMapping("/wechatBlacklistPrv/findWechatBlacklistTypeSelect")
    public Object findWechatBlacklistTypeSelect(){
        List<SelectKeyVo> selectIdVoList = new ArrayList<>();

        for (WechatBlacklistTypeEnum wechatBlacklistTypeEnum : WechatBlacklistTypeEnum.values()){
            SelectKeyVo selectKeyVo = new SelectKeyVo();
            selectKeyVo.setKey(String.valueOf(wechatBlacklistTypeEnum.getValue()));
            selectKeyVo.setValue(wechatBlacklistTypeEnum.getDesc());
            selectIdVoList.add(selectKeyVo);
        }
        return selectIdVoList;
    }

    @SystemLogType(model = SystemModelEnum.WechatBlacklistPrv, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "取消共享至全网", notes = "取消共享至全网")
    @ApiOperationSupport(order = 8)
    @PostMapping("/wechatBlacklistPrv/cancleWechatBlacklistPub")
    public Object cancleWechatBlacklistPub(@RequestBody WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto){
        wechatBlacklistPrvService.cancelWechatBlacklistPub(wechatBlacklistPrvIdDto);
        return true;
    }

}
